package com.itqf.xiaomi.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.itqf.xiaomi.dto.CommonsDto;
import com.itqf.xiaomi.dto.ProductDto;
import com.itqf.xiaomi.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * projectName: springboot_part
 *
 * @author: 赵伟风
 * time: 2021/9/26 17:07
 * description:
 */
@RestController
@CrossOrigin("*")
@RequestMapping("product")
public class ProductController {
    @Autowired
    private ProductService productService;

    /**
     * 根据类别查询6个商品信息
     * @param
     * @return
     */
    @PostMapping("getPromoProduct")
    public Object getPromoProduct(@RequestBody CommonsDto commonsDto) throws JsonProcessingException {

        Object r = productService.getPromoProduct(commonsDto.getCategoryName());

        return r;
    }

    /**
     * 查询对应类型,热门商品的信息 查询六个!
     * @param productDto
     * @return
     */
    @PostMapping("getHotProduct")
    public Object getHotProduct(@RequestBody ProductDto productDto){
        Object r = productService.getHotProduct(productDto);
        return r;
    }


    /**
     * 按类别和分页查询商品
     * @param productDto
     * @return
     */
    @PostMapping("getProductByCategory")
    public Object getProductByCategory(@RequestBody ProductDto productDto){

        Object r = productService.getProductByCategory(productDto);

        return r;
    }


    /**
     * 查询类别数据
     * @return
     */
    @PostMapping("getCategory")
    public Object getCategory(){

        Object r = productService.getCategory();

        return r;
    }

    /**
     * 查询全部商品
     * @param productDto
     * @return
     */
    @PostMapping("getAllProduct")
    public Object getAllProduct(@RequestBody ProductDto productDto){
        Object r = productService.getProductByCategory(productDto);
        return r;
    }


    /**
     * 查询商品详情
     * @param commonsDto
     * @return
     */
    @PostMapping("getDetails")
    public Object getAllProduct(@RequestBody CommonsDto commonsDto){
        Object r = productService.getDetails(commonsDto.getProductID());
        return r;
    }


    /**
     * 查询商品id对应的图片数据
     * @param commonsDto
     * @return
     */
    @PostMapping("getDetailsPicture")
    public Object getDetailsPicture(@RequestBody CommonsDto commonsDto){
        Object r = productService.getDetailsPicture(commonsDto.getProductID());
        return r;
    }





}
